import { useMemberStore } from "@/stores/modules/memberStore";
import { ref } from "vue";
import AddressPanel from "../components/AddressPanel.vue";

export const useGoodPopup = () => {
    const memberStore = useMemberStore();

    // 弹出层实例
    const popupRef = ref<UniHelper.UniPopupInstance>();

    // 弹出层类型名称
    const popupName = ref<'address' | 'service'>('service');

    // 开启弹出层
    const openPopup = (name: typeof popupName.value) => {
        // 检测是否登录
        if (name === 'address' && !memberStore.profile) {
            return uni.navigateTo({ url: '/pages/login/login' });
        }
        popupName.value = name;
        popupRef.value?.open!();
    };

    // 地址面板实例
    const addressPanelRef = ref<InstanceType<typeof AddressPanel>>();

    return { popupRef, popupName, openPopup, addressPanelRef };
};